<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/themes/default/css/umeditor.css" type="text/css"
	rel="stylesheet">

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8"
	src="js/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="js/umeditor.min.js"></script>
<script type="text/javascript" src="js/lang/zh-cn/zh-cn.js"></script>
<script src="js/content.js"></script>


	
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="js/bootstrap.min.js"></script>
	<script type="text/javascript"src="js/button.js"></script>
	<style>
	button{
		margin-right:20px;
	}
	li{
		height:55px;
	}
	li span{
		margin-right:20px;
		float:right;
	}
	.edui-container {
		margin:0 auto;
	}
	</style>
</head>

<body>
<div class="site-header jumbotron" style="margin-bottom:0">
  <h1 style="text-align: center">Welcome To BBS!</h1>
  <div style="text-align: right">
    <c:choose>
  <c:when test="${not empty user }">
   <button  class="btn btn-info" id="changepsw">修改密码</button>
  <button  class="btn btn-warning" id="logout">注销</button>
  </c:when>
  <c:otherwise>
  <button  class="btn btn-primary" id="login">登录</button>
  <button  class="btn btn-success" id="register">注册</button>
  </c:otherwise>
  </c:choose> 
  </div>
</div>
<ul class="nav nav-tabs" style="margin-top:0">
  <li role="presentation"><a href="index.action">Home</a></li> 
</ul>
	<h3>${data.rows[0].cate.name }</h3>
	<br>
	
	<ul class="list-group">
	<c:forEach var="content" items="${data.rows}">
 	 	<li class="list-group-item">
 	 	<a href="page.action?content=${content.id }">${content.title }</a>
 	 	<br>
 	 	<span>${content.createDate }</span>
 	 	<span>${content.user.username }</span>
 	 	<c:if test="${user.role.id==2 }">
		<span><a href="delContent.action?cate=${cate }&id=${content.id} " onclick="if(confirm('确定删除?')==false)return false;">删除</a></span>
		</c:if>
 	 	</li>
  	</c:forEach>

</ul>
	<div>
		<c:if test="${data.hasLast() }">
			<a href="content.action?cate=${cate }&page=${data.page-1}&rows=${data.num}">上一页</a>
		</c:if>
		<span>第${data.page}页</span>
		<c:if test="${data.hasNext() }">
			<a href="content.action?cate=${cate }&page=${data.page+1}&rows=${data.num}">下一页</a>
		</c:if>

	</div>


	<c:if test="${not empty user }">
		<div>
			<h3>发表帖子</h3>
		</div>
		<form action="post.action" method="post" id="form">
			<input type="hidden" name="cate" value="${cate }"> 
			<div style="text-align: center">
			<input type="text" name="title" style="width:600px;height:30px;margin:10px">
			</div>
			<script type="text/plain" id="myEditor" style="width:700px;height:380px;" name="content"></script>

			<div class="btn-group" style="margin:20px 300px 20px;float:right">
			<button  class="btn btn-success"id="submit" >发布</button>
			</div>
		</form>
	</c:if>
	<script type="text/javascript">
		//实例化编辑器
		var um = UM.getEditor('myEditor');
		um.addListener('blur', function() {
			$('#focush2').html('编辑器失去焦点了')
		});
		um.addListener('focus', function() {
			$('#focush2').html('')
		});
		//按钮的操作
		function insertHtml() {
			var value = prompt('插入html代码', '');
			um.execCommand('insertHtml', value)
		}
		function isFocus() {
			alert(um.isFocus())
		}
		function doBlur() {
			um.blur()
		}
		function createEditor() {
			enableBtn();
			um = UM.getEditor('myEditor');
		}
		function getAllHtml() {
			alert(UM.getEditor('myEditor').getAllHtml())
		}
		function getContent() {
			var arr = [];
			arr.push("使用editor.getContent()方法可以获得编辑器的内容");
			arr.push("内容为：");
			arr.push(UM.getEditor('myEditor').getContent());
			alert(arr.join("\n"));
		}
		function getPlainTxt() {
			var arr = [];
			arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
			arr.push("内容为：");
			arr.push(UM.getEditor('myEditor').getPlainTxt());
			alert(arr.join('\n'))
		}
		function setContent(isAppendTo) {
			var arr = [];
			arr.push("使用editor.setContent('欢迎使用umeditor')方法可以设置编辑器的内容");
			UM.getEditor('myEditor').setContent('欢迎使用umeditor', isAppendTo);
			alert(arr.join("\n"));
		}
		function setDisabled() {
			UM.getEditor('myEditor').setDisabled('fullscreen');
			disableBtn("enable");
		}

		function setEnabled() {
			UM.getEditor('myEditor').setEnabled();
			enableBtn();
		}

		function getText() {
			//当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
			var range = UM.getEditor('myEditor').selection.getRange();
			range.select();
			var txt = UM.getEditor('myEditor').selection.getText();
			alert(txt)
		}

		function getContentTxt() {
			var arr = [];
			arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
			arr.push("编辑器的纯文本内容为：");
			arr.push(UM.getEditor('myEditor').getContentTxt());
			alert(arr.join("\n"));
		}
		function hasContent() {
			var arr = [];
			arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
			arr.push("判断结果为：");
			arr.push(UM.getEditor('myEditor').hasContents());
			alert(arr.join("\n"));
		}
		function setFocus() {
			UM.getEditor('myEditor').focus();
		}
		function deleteEditor() {
			disableBtn();
			UM.getEditor('myEditor').destroy();
		}
		function disableBtn(str) {
			var div = document.getElementById('btns');
			var btns = domUtils.getElementsByTagName(div, "button");
			for (var i = 0, btn; btn = btns[i++];) {
				if (btn.id == str) {
					domUtils.removeAttributes(btn, [ "disabled" ]);
				} else {
					btn.setAttribute("disabled", "true");
				}
			}
		}
		function enableBtn() {
			var div = document.getElementById('btns');
			var btns = domUtils.getElementsByTagName(div, "button");
			for (var i = 0, btn; btn = btns[i++];) {
				domUtils.removeAttributes(btn, [ "disabled" ]);
			}
		}
	</script>
</body>
</html>
